{extend name="common/base_page" /}

{block name="title"}{$page_title}人员角色信息{/block}

{block name="jscssfile"}
<link href="__ADMIN__/css/plugins/iCheck/custom.css?v={$site.version}" rel="stylesheet">
<script src="__ADMIN__/js/plugins/iCheck/icheck.min.js"></script>
{/block}

{block name="css"}
<style type="text/css">
textarea{max-width: 260px;}
.layui-form-checkbox { display: none; }
</style>
{/block}

{block name="body"}
  <div class="layui-fluid" style="height: 100vh;overflow-y: scroll;">
    <div class="layui-card">
      <div class="layui-card-header">{$page_title}人员角色信息</div>
      <div class="layui-card-body" style="padding: 15px;">
        <form class="layui-form" action="" lay-filter="component-form-group">

          <div class="layui-form-item">
            <label class="layui-form-label">角色名称</label>
            <div class="layui-input-inline">
              <input type="text" name="user_name" lay-verify="name" maxlength="18" autocomplete="off" class="layui-input" value="{$info.name}"/>
            </div>
            <div class="layui-form-mid layui-word-aux">请填写角色名称</div>
          </div>

          <div class="layui-form-item">
            <div class="layui-inline" style="padding-bottom:10px;">
              <label class="layui-form-label">上级角色</label>
              <div class="layui-input-inline">
                  <select id="group_id" name="group_id">
                    <option value="0" {if $info.pid eq '0'}selected="true"{/if}>顶级角色</option>
                    {volist name="group_list" id="vo"}
                    <option value="{$vo.id}" {if $info.pid eq $vo.id}selected="true"{/if}>{$vo.name}</option>
                    {/volist}
                </select>
              </div>
          </div>

          <div class="layui-form-item">
            <div class="layui-inline" style="padding-bottom:10px;">
              <label class="layui-form-label">默认工作台</label>
              <div class="layui-input-inline">
                  <select id="index_page" name="index_page">
                    {volist name="work_page_list" id="vo"}
                    <option value="{$vo.url}" {if $info.index_page eq $vo.url}selected="true"{/if}>{$vo.name}</option>
                    {/volist}
                </select>
              </div>
              <div class="layui-form-mid layui-word-aux">角色默认使用的工作台，若1人担任多个角色，请选择通用工作台</div>
          </div>

          <div class="layui-form-item">
            <label class="layui-form-label">角色状态</label>
            <div class="layui-input-block">
              <input type="checkbox" {if !$info || $info.status gt 0}checked="true"{/if} name="open" lay-skin="switch" lay-filter="component-form-switchTest" lay-text="启用|停用">
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
              <textarea name="remark" placeholder="请输入备注内容" class="layui-textarea"></textarea>
            </div>
          </div>

{if $info.is_supper_admin elt 0}
          <div class="layui-form-item">
            <label class="layui-form-label">权限配置</label>
            <div class="layui-input-block" id="rulebox">
                {if $info}
                    {include file="common/inc_setrules_edit" /}
                {else}
                    {include file="common/inc_setrules_add" /}
                {/if}
            </div>
          </div>
{else}
<script>function getCheckedValueForArr(){ return ''; }</script>
{/if}

          <div class="layui-form-item layui-layout-admin">
            <div class="layui-input-block">
              <div class="layui-footer" style="left: 0;">
                <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="component-form-demo1">保存</button>
                <button type="reset" class="layui-btn layui-btn-danger" id="resetBtn">重置</button>
                <a class="layui-btn layui-btn-primary" href="{:url('index/clinic.admin_group/index')}">返回</a>
              </div>
            </div>
          </div>
          <input type="hidden" name="id" value="{$info.id}"/>
        </form>
      </div>
    </div>
  </div>
{/block}

{block name="script"}
<script type="text/javascript">
$(function(){
  setTimeout(function(){
    $(".layui-form :input[name='user_name']").focus();
  },100);
  $('.i-checks').iCheck({
      checkboxClass: 'icheckbox_square-green',
      radioClass: 'iradio_square-green',
  });
});

layui.use(['form'], function(){
    form = layui.form;
    form.render(null, 'component-form-group');
    /* 自定义验证规则 */
    form.verify({
      name: [/(.+){1,18}$/, '必须填写1到18位角色名称']
    });
    /* 监听提交 */
    form.on('submit(component-form-demo1)', function(data){
      let objData = data.field;
      objData.rules = getCheckedValueForArr();
      //console.log(JSON.stringify(objData)); //最终的提交信息
      layer.confirm('确定要保存角色信息吗？', {
          title:'保存',shade:[0.4,'#000000'],btn: ['确定','取消'],
          btn1:function(){
              layer.closeAll();
              _Index.ajax("{:url('index/clinic.admin_group/info')}",objData,function(d){
                if(d.err == 0)
                {
                  $('#resetBtn').trigger('click');
                  layer.msg(d.msg, {time: 1000},function(){ 
                    window.location.href = "{:url('index/clinic.admin_group/index')}";
                  });
                }else{
                  layer.msg(d.msg, {time: 2000,anim: 4});
                }
              },'请稍候...');
          }
      });
      return false;
    });
  });
</script>
{/block}